<html>
<head><meta charset="utf-8"><title>Non exhaustive reachable patterns lint compiler-team#445 · t-compiler/major changes · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/index.html">t-compiler/major changes</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html">Non exhaustive reachable patterns lint compiler-team#445</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="245520784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/245520784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> triagebot <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#245520784">(Jul 10 2021 at 00:43)</a>:</h4>
<p>A new proposal has been announced: <a href="https://github.com/rust-lang/compiler-team/issues/445">Non exhaustive reachable patterns lint #445</a>. It will be announced at the next meeting to try and draw attention to it, but usually MCPs are not discussed during triage meetings. If you think this would benefit from discussion amongst the team, consider proposing a design meeting.</p>



<a name="245558820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/245558820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#245558820">(Jul 10 2021 at 16:08)</a>:</h4>
<p>As a procedural note, a new lint would be lang; the implementation of it would be compiler.</p>



<a name="245559416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/245559416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#245559416">(Jul 10 2021 at 16:22)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> should this be closed and <span class="user-mention" data-user-id="243877">@DevinR528</span> open an MCP for the lang team?</p>



<a name="245559903"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/245559903" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#245559903">(Jul 10 2021 at 16:33)</a>:</h4>
<p>If there's stuff for the compiler team to review as well, this would be a fine place for that. Just observing that new lints need a lang review as well.</p>



<a name="245559943"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/245559943" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#245559943">(Jul 10 2021 at 16:34)</a>:</h4>
<p>But yes, a lang MCP would be helpful.</p>



<a name="245559955"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/245559955" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#245559955">(Jul 10 2021 at 16:34)</a>:</h4>
<p>I wouldn't expect this to be <em>such</em> a large impl change that it needs a compiler MCP just to see if it's feasible.</p>



<a name="245560220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/245560220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#245560220">(Jul 10 2021 at 16:41)</a>:</h4>
<p>(that said, if the lang MCP is accepted, <span class="user-mention silent" data-user-id="245339">Nadrieril</span> is a good person to talk to about exhaustiveness checking)</p>



<a name="245566611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/245566611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> inquisitivecrystal <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#245566611">(Jul 10 2021 at 19:18)</a>:</h4>
<p>My understanding of the relevant policy was derived from <a href="#narrow/stream/131828-t-compiler/topic/New.20lint.20.28declaring.20an.20uncallable.20function.29.20.28.2385520.29/near/244205129">this message from Wesley Wiser</a>, which states that there's usually a compiler MCP first.</p>
<p>Might it make sense to document the relevant procedure somewhere, such as in the rustc dev guide?</p>



<a name="245600605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/245600605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DevinR528 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#245600605">(Jul 11 2021 at 10:38)</a>:</h4>
<p>So we wait until FCP and add members of the lang team to that? Otherwise, leave the MCP where it is and send a message to the lang stream or mention the lang team in the MCP so they are aware?</p>



<a name="246711423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/233931-t-compiler/major%20changes/topic/Non%20exhaustive%20reachable%20patterns%20lint%20compiler-team%23445/near/246711423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> DevinR528 <a href="https://rust-lang.github.io/zulip_archive/stream/233931-t-compiler/major-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20compiler-team.23445.html#246711423">(Jul 21 2021 at 12:25)</a>:</h4>
<p>I've been working on two options, there is now a WIP lint <a href="https://github.com/DevinR528/rust/commit/df377ca309fd5acf1a3dcdcb90ecdfef9578eafb">inside usefulness.rs</a> and a <a href="https://github.com/rust-lang/rust/pull/86809/commits/6ca98791848e07d0115d56d459fc8e57c432170f">normal lint</a>. There is a rather large problem in the normal lint, it cannot detect guards or or-patterns, basically it would have to use/reimplement parts of the mechanics of <a href="https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/check_match.rs">check_match</a>. It seems to me that adding the lint to the usefulness and check_match files makes sense.</p>
<p>I was able to make the lint work for <a href="https://github.com/DevinR528/rust/commit/df377ca309fd5acf1a3dcdcb90ecdfef9578eafb">enums</a> but am having trouble with structs and variants with fields <a href="https://github.com/DevinR528/rust/commits/useful-reachable">WIP commits</a>. Not really sure how to go about checking for the attribute (either place, see bellow) or the best way to skip the <code>..</code> rest/wildcardish and check for missing fields.</p>
<p>The other issue is where the attribute should be placed? In the <a href="https://github.com/rust-lang/rust/issues/84332">issue</a> as well as the <code>non_exhaustive</code> PR <a href="https://github.com/rust-lang/rust/issues/44109#issuecomment-521781237">comments</a> it was mentioned adding the attribute to the wildcard in a match</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">match</span><span class="w"> </span><span class="n">Bar</span>::<span class="n">A</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Bar</span>::<span class="n">A</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{},</span><span class="w"></span>
<span class="w">    </span><span class="n">Bar</span>::<span class="n">B</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{},</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[deny(reachable)]</span><span class="w"> </span><span class="c1">// attribute goes here or on the expression</span>
<span class="w">    </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="c1">// triggers lint "missing Bar::C..."</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>The problem with this is that it's struct counterpart  isn't exactly valid <a href="https://github.com/rust-lang/rust/issues/81282">issue</a></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">Foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">a</span><span class="w"></span>
<span class="w">    </span><span class="n">b</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="cp">#[warn(reachable)]</span><span class="w"></span>
<span class="w">    </span><span class="o">..</span><span class="w"> </span><span class="c1">// triggers lint "missing field `c`..."</span>
<span class="p">}</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">structure</span><span class="p">;</span><span class="w"></span>
</code></pre></div>
<p>So the options are to make this valid or put the attribute on the expr/stmt instead of the wild patterns.</p>
<p>I also opened a lang-team <a href="https://github.com/rust-lang/lang-team/issues/112">https://github.com/rust-lang/lang-team/issues/112</a> and zulip <a href="#narrow/stream/243200-t-lang.2Fmajor-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112">https://rust-lang.zulipchat.com/#narrow/stream/243200-t-lang.2Fmajor-changes/topic/Non.20exhaustive.20reachable.20patterns.20lint.20lang-team.23112</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>